package interoperability
	
import javax.xml.transform.TransformerFactory
import javax.xml.transform.Transformer
import javax.xml.transform.stream.StreamResult
import javax.xml.transform.stream.StreamSource
import com.hp.hpl.jena.rdf.model.*
import com.hp.hpl.jena.query.*
import com.hp.hpl.jena.graph.*
import com.hp.hpl.jena.ontology.*
import com.talis.rdfwriters.json.*;

class RenderFactsService {
	static scope= "request"
	static transactional = false
		
    def buildRdfNt() {
		def model= ModelFactory.createDefaultModel()
		def canConnectTo= ResourceFactory.createProperty('http://www.jpdo.gov/nextgen#canConnectTo')
		nextgen.Interoperability.list().each { f ->
			def subject= model.createResource(f.fromUrl)
			def object= model.createResource(f.toUrl)
			model= model.add(model.createStatement(subject, canConnectTo, object))
		}
		def out= new FileOutputStream('web-app/resources/interoperability.nt')
		def rdfWriter= model.getWriter('N-TRIPLE')
		rdfWriter.write(model, out, 'http://www.jpdo.gov/interoperability')
		out.close()
    }
	
	def buildRdfJson() {
		def model= ModelFactory.createDefaultModel()
		def canConnectTo= ResourceFactory.createProperty('http://www.jpdo.gov/nextgen#canConnectTo')
		nextgen.Interoperability.list().each { f ->
			def subject= model.createResource(f.fromUrl)
			def object= model.createResource(f.toUrl)
			model= model.add(model.createStatement(subject, canConnectTo, object))
		}
		def out= new FileOutputStream('web-app/resources/interoperability.json')
		def jsonWriter= new JSONJenaWriter()
		jsonWriter.write(model, out, 'http://www.jpdo.gov/interoperability')
		out.close()
	}
}
